
package picsim;

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;

// netbeans -> layoutmanager

import org.netbeans.lib.awtextra.*;

/**
 *
 * @author Daniel
 * @brief Erstellt das bzw. die Fenster der Anwendung. Anpassungen der GUI werden hier gesteuert.
 *
 */

public class GUI implements ActionListener {

    // initial objects of classes
    Control control;
    MemMan mem;
    PIC pic;
    Calculator calc;
    Breakpoint bp;

    LineNumber line;
    // *********

    Thread simTh;
    
    JFrame mainGUI = new JFrame("PIC-Simulator");
    JFrame settingsGUI;

    private static final Color HILIT_COLOR = Color.YELLOW; // color for breakpoint highlighter    
    
    // declare GUI-items below...
    private JMenu menu, submenu;

    private JMenuItem menuItem; // items without ActionListener (no function so far...)
    private JMenuItem menuItem_closeApp, menuItem_about, menuItem_openFile, menuItem_reset, menuItem_Setting_bp, menuItem_docu; // items with ActionListener

    JRadioButtonMenuItem rbMenuItem;
    JRadioButtonMenuItem rbMenuItem_normalSpeed;

    //private JTextArea codeArea;
    private JEditorPane codeArea;

    private JCheckBox bank1_check;
    private JCheckBox comport_check;

    private JTextField wReg, pcl;
    private JTextField tmr0_hex, pclSFR_hex, status_hex, fsr_hex, portA_hex, portB_hex, eedata_hex, eeadr_hex, pclath_hex, intcon_hex;
    private JTextField optionReg_hex, trisA_hex, trisB_hex, eecon1_hex;
    private JTextField instructionCounter;
    private JTextField realTimeDuration;
    private JTextField clockCycles;

    private JTextField bank0[] = new JTextField[68];
    //private JTextField bank1[] = new JTextField[68];
    //private JTextField sfr[] = new JTextField[15];
    private JTextField tmr0_bit[] = new JTextField[8];
    private JTextField pclSFR_bit[] = new JTextField[8];
    private JTextField status_bit[] = new JTextField[8];
    private JTextField fsr_bit[] = new JTextField[8];
    private JTextField portA_bit[] = new JTextField[5];
    private JTextField portB_bit[] = new JTextField[8];
    private JTextField eedata_bit[] = new JTextField[8];
    private JTextField eeadr_bit[] = new JTextField[8];
    private JTextField pclath_bit[] = new JTextField[5];
    private JTextField intcon_bit[] = new JTextField[8];
    private JTextField optionReg_bit[] = new JTextField[8];
    private JTextField trisA_bit[] = new JTextField[5];
    private JTextField trisB_bit[] = new JTextField[8];
    private JTextField eecon1_bit[] = new JTextField[5];
    private JTextField stack[] = new JTextField[8];

    // settings
    private JTextField bp_input[] = new JTextField[10];
    
    private JLabel gpr_label;
    private JLabel sfr_label;
    private JLabel codeAreaLabel;
    private JLabel wReg_label, pcl_label;
    private JLabel sfr_bit_label;
    private JLabel tmr0_label, pclSFR_label, status_label, fsr_label, portA_label, portB_label, eedata_label, eeadr_label, pclath_label, intcon_label;
    private JLabel optionReg_label, trisA_label, trisB_label, eecon1_label;
    private JLabel comport_label;

    private JLabel bank1_checkLabel;

    private JLabel bank0_label[] = new JLabel[68];
    private JLabel bank1_label[] = new JLabel[68];
    private JLabel sfr_bit[] = new JLabel[8];
    private JLabel stack_IndexLabel[] = new JLabel[8];

    private JLabel instructionCounter_label;
    private JLabel realTimeDuration_label;
    private JLabel clockCycles_label;
    private JLabel stack_label;

    private JScrollPane scrollGPR;
    private JScrollPane scrollSFR;

    private JPanel panelGPR;
    private JPanel panelSFR;
    
    private JToolBar toolBar;
    /* Toolbar Buttons */ private JButton bt_reset, bt_startPause, bt_open, bt_stop, bt_step;

    private Color colorBitCleared = new Color(255, 255, 255); // white
    private Color colorBitSet = new Color(255, 0, 0); // red
    // *********

    
    /**
     * @brief Konstruktor der Klasse GUI
     */
    public GUI() {

        mem = new MemMan(this);
        pic = new PIC(mem);
        bp = new Breakpoint();

        control = new Control(this, mem, pic, bp);

        calc = new Calculator();

        initMainGUI();

    }

    /**
     * @brief Methode bereitet das Fenster bzw. die GUI für die Anzeige vor.
     * Besonderheit: Fenster wird in der Mitte des Bildschirmes angezeigt.
     */
    private void initMainGUI() {
        // TODO Content of window
        Dimension dim,size;
        Point pos;

        dim = Toolkit.getDefaultToolkit().getScreenSize();
        size = new Dimension(800,600);

        // Prepare window
        
        // justify window (center of screen)
        pos = new Point();
        pos.x = (dim.width - size.width) / 2;
        pos.y = (dim.height - size.height) / 2;
        // *********

        // draw window
        //JFrame mainGUI = new JFrame("PIC-Simulator");
        mainGUI.setSize(size);
        mainGUI.setLocation(pos);
        mainGUI.setResizable(false);
        mainGUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainGUI.setLayout(null);
        // *********

        // set LAF (L&F = Look and Feel) of window       
        LAFEinstellung.setNativeLookAndFeel();
        // *********

        // create content of GUI
        createAndSetContent();
        // *********

        // refresh GUI to show the right values on power-on
        refreshGUI();
        // *********

        // show window
        mainGUI.setVisible(true);
        // *********
    }

    /**
     *
     * @return JMenuBar
     * @brief erzeugt die Menüleiste der GUI
     *
     */
    private JMenuBar createMenuBar() {

        // TODO create menubar and insert interactions
        // declare new items in Class GUI (otherwise the item has no function)
        JMenuBar menuBar;        
    
        menuBar = new JMenuBar();

        // Build the "Datei" menu.
        menu = new JMenu("Datei");

        // MenuItems
        menuItem_openFile = new JMenuItem("Quelltext öffnen");
        menuItem_openFile.addActionListener(this);
        menuItem_openFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
        menuItem_openFile.setMnemonic((int)'O');
        menu.add(menuItem_openFile);

        menuItem_reset = new JMenuItem("Simulator zurücksetzen");
        menuItem_reset.addActionListener(this);
        menuItem_reset.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));
        menuItem_reset.setMnemonic((int)'R');
        menu.add(menuItem_reset);

        menu.addSeparator();

        menuItem_closeApp = new JMenuItem("Beenden");
        menuItem_closeApp.addActionListener(this);
        menuItem_closeApp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, Event.CTRL_MASK));
        menuItem_closeApp.setMnemonic((int)'Q');
        menu.add(menuItem_closeApp);

        menuBar.add(menu);
        // *********


        // Build the "Einstellungen" menu.
        menu = new JMenu("Einstellungen");
        submenu = new JMenu("Geschwindigkeit");
        
        ButtonGroup group = new ButtonGroup();

        rbMenuItem = new JRadioButtonMenuItem("Langsam");
        group.add(rbMenuItem);
        rbMenuItem.addActionListener(this);
        submenu.add(rbMenuItem);

        rbMenuItem_normalSpeed = new JRadioButtonMenuItem("Normal");
        rbMenuItem_normalSpeed.setSelected(true); // Standard
        group.add(rbMenuItem_normalSpeed);
        rbMenuItem_normalSpeed.addActionListener(this);
        submenu.add(rbMenuItem_normalSpeed);

        rbMenuItem = new JRadioButtonMenuItem("Schnell");
        group.add(rbMenuItem);
        rbMenuItem.addActionListener(this);
        submenu.add(rbMenuItem);
        menu.add(submenu);

        menu.addSeparator();

        menuItem_Setting_bp = new JMenuItem("Breakpoints");
        menuItem_Setting_bp.addActionListener(this);
        menu.add(menuItem_Setting_bp);
        
        menuBar.add(menu);
        // *********

        // Build the "Hilfe" menu.
        menu = new JMenu("Hilfe");

        // MenuItems
        menuItem_docu = new JMenuItem("Dokumentation aufrufen");
        menuItem_docu.addActionListener(this);
        menu.add(menuItem_docu);

        menuItem_about = new JMenuItem("Über...");
        menuItem_about.addActionListener(this);
        menu.add(menuItem_about);

        menuBar.add(menu);
        // *********

        return menuBar;

    }

    /**
     * @brief Methode, die die GUI-Elemente der GUI erzeugt und einbindet.
     */
    public void createAndSetContent() {

        // create a menubar and fill with items
        mainGUI.setJMenuBar(createMenuBar());
        // *********

        // create toolbar
        mainGUI.add(createToolBar());
        // *********


        // set status of file close buttons
        setResetStatus(false);
        // *********


        // create textarea for code-preview
        codeAreaLabel = new JLabel("Code Ansicht:");
        codeAreaLabel.setBounds(10, 40, 100, 15);
        mainGUI.add(codeAreaLabel);

        JScrollPane codeArea_scroll = new JScrollPane();
        codeArea = new JEditorPane();

        codeArea.setFont(new Font("Courier New", Font.PLAIN, 11));
        codeArea.setEditable(false);

        codeArea_scroll.setViewportView(codeArea);
        codeArea_scroll.setBounds(10, 60, 280, 480); // (int x, int y, int width, int height)

        LineNumber lineNumber = new LineNumber(codeArea);
        codeArea_scroll.setRowHeaderView(lineNumber);

        mainGUI.add(codeArea_scroll);
        // *********


        // create PCL and W register fields
        // W-Reg.
        wReg_label = new JLabel("W-Register:");
        wReg_label.setBounds(305, 400, 60, 20); // (int x, int y, int width, int height)
        mainGUI.add(wReg_label);

        wReg = new JTextField();
        wReg.setBounds(380, 400, 40, 20); // (int x, int y, int width, int height)
        mainGUI.add(wReg);

        
        // PCL
        pcl_label = new JLabel("PCL:");
        pcl_label.setBounds(305, 425, 60, 20); // (int x, int y, int width, int height)
        mainGUI.add(pcl_label);

        pcl = new JTextField();
        pcl.setBounds(380, 425, 40, 20); // (int x, int y, int width, int height)
        mainGUI.add(pcl);
        // *********

        // instruction counter
        instructionCounter_label = new JLabel("Befehlszähler:");
        instructionCounter_label.setBounds(305, 450, 100, 20);
        mainGUI.add(instructionCounter_label);

        instructionCounter = new JTextField();
        instructionCounter.setBounds(380, 450, 60, 20);
        mainGUI.add(instructionCounter);
        // *********


        // real time duration
        realTimeDuration_label = new JLabel("Laufzeit:");
        realTimeDuration_label.setBounds(305, 475, 100, 20);
        mainGUI.add(realTimeDuration_label);

        realTimeDuration = new JTextField("");
        realTimeDuration.setBounds(380, 475, 60, 20);
        mainGUI.add(realTimeDuration);
        // *********


        // Bank1
        bank1_checkLabel = new JLabel("Bank 1:");
        bank1_checkLabel.setBounds(305, 500, 60, 20);
        mainGUI.add(bank1_checkLabel);

        bank1_check = new JCheckBox();
        bank1_check.setBounds(377, 500, 25, 20);
        bank1_check.setEnabled(false);
        mainGUI.add(bank1_check);
        // *********

        // Comport
        comport_label = new JLabel("Comport:");
        comport_label.setBounds(305, 520, 60, 20);
        mainGUI.add(comport_label);

        comport_check = new JCheckBox();
        comport_check.setBounds(377, 520, 25, 20);
        comport_check.addActionListener(this);
        disableComportBox();
        mainGUI.add(comport_check);
        // *********

        // create stack view
        stack_label = new JLabel("Stack:");
        stack_label.setBounds(535, 400, 60, 20);
        mainGUI.add(stack_label);

        int nexty = 420;
        for(int i=0;i<8;i++) {
            stack_IndexLabel[i] = new JLabel("["+i+"]");
            stack_IndexLabel[i].setBounds(535, nexty, 40, 15);
            mainGUI.add(stack_IndexLabel[i]);

            stack[i] = new JTextField("00h");
            stack[i].setBounds(555, nexty, 40, 15);
            mainGUI.add(stack[i]);
            nexty+=15;
        }
        // *********


        // create GPRs panel
        gpr_label = new JLabel("General Purpose Registers (GPRs):");
        gpr_label.setBounds(610, 40, 200, 15); // (int x, int y, int width, int height)
        mainGUI.add(gpr_label);

        scrollGPR = new JScrollPane();
        panelGPR = new JPanel();
        panelGPR.setLayout(new AbsoluteLayout());
        
        scrollGPR.setViewportView(panelGPR);
        scrollGPR.setBounds(610, 60, 170, 480); // (int x, int y, int width, int height)

        // create bank0 fields
        int x = 0, y = 5, height = 15, width = 40; // values for postitioning within the panel
        int start = 0xC; // 000Ch = 12 (dez)
        int wrap = 33;

        for(int i=0; i<68; i++) {

            String hexValue = Integer.toHexString(start);
            bank0_label[i] = new JLabel(hexValue.toUpperCase()+"h", SwingConstants.RIGHT); // text orientation = right, make letters uppercase
            bank0[i] = new JTextField("00h");

            if(i<=wrap) {
                panelGPR.add(bank0_label[i], new AbsoluteConstraints(x, y-3, 25, 20)); // (int x, int y, int width, int height)                
                panelGPR.add(bank0[i], new AbsoluteConstraints(x+30, y, width, height)); // (int x, int y, int width, int height)
            }
            else {
                x = 70;
                panelGPR.add(bank0_label[i], new AbsoluteConstraints(x, y-3, 25, 20)); // (int x, int y, int width, int height)
                panelGPR.add(bank0[i], new AbsoluteConstraints(x+30, y, width, height)); // (int x, int y, int width, int height)
            }

            if(i == wrap) y = 5;
            else y = y+height;
            start++; // next register adress
        }

        mainGUI.add(scrollGPR);
        // *********


        // create SFRs panel
        sfr_label = new JLabel("Special Function Registers (SFRs):");
        sfr_label.setBounds(305, 40, 200, 15); // (int x, int y, int width, int height)
        mainGUI.add(sfr_label);

        scrollSFR = new JScrollPane();
        panelSFR = new JPanel();
        panelSFR.setLayout(new AbsoluteLayout());

        scrollSFR.setViewportView(panelSFR);
        scrollSFR.setBounds(305, 60, 290, 330); // (int x, int y, int width, int height)


        // create SFR fields
        sfr_bit_label = new JLabel("Bit");
        panelSFR.add(sfr_bit_label, new AbsoluteConstraints(200, 5, 55, 20));

        x = 140;
        int i = 7;

        while(i>=0) {
            sfr_bit[i] = new JLabel(Integer.toString(i));
            panelSFR.add(sfr_bit[i], new AbsoluteConstraints(x, 20, 10, 20));

            x+=18;
            i--;
        }

        // TMR0
        tmr0_label = new JLabel("01h TMR0");
        panelSFR.add(tmr0_label, new AbsoluteConstraints(5, 40, 55, 20)); // (int x, int y, int width, int height)

        tmr0_hex = new JTextField("00h");
        panelSFR.add(tmr0_hex, new AbsoluteConstraints(100, 40, 27, 20)); // (int x, int y, int width, int height)

        x = 137;
        i = 7;
        y = 43;

        while(i>=0) {
            tmr0_bit[i] = new JTextField();
            tmr0_bit[i].setEnabled(false);
            tmr0_bit[i].setBackground(Color.WHITE);
            panelSFR.add(tmr0_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        // PCL
        pclSFR_label = new JLabel("02h PCL");
        panelSFR.add(pclSFR_label, new AbsoluteConstraints(5, 60, 90, 20));

        pclSFR_hex = new JTextField("00h");
        panelSFR.add(pclSFR_hex, new AbsoluteConstraints(100, 60, 27, 20));

        x = 137;
        i = 7;
        y = 63;

        while(i>=0) {
            pclSFR_bit[i] = new JTextField();
            pclSFR_bit[i].setEnabled(false);
            pclSFR_bit[i].setBackground(Color.WHITE);
            panelSFR.add(pclSFR_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        // Status
        status_label = new JLabel("03h STATUS");
        panelSFR.add(status_label, new AbsoluteConstraints(5, 80, 90, 20));

        status_hex = new JTextField("00h");
        panelSFR.add(status_hex, new AbsoluteConstraints(100, 80, 27, 20));

        x = 137;
        i = 7;
        y = 83;

        while(i>=0) {
            status_bit[i] = new JTextField();
            status_bit[i].setEnabled(false);
            status_bit[i].setBackground(Color.WHITE);
            panelSFR.add(status_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        // FSR
        fsr_label = new JLabel("04h FSR");
        panelSFR.add(fsr_label, new AbsoluteConstraints(5, 100, 90, 20));

        fsr_hex = new JTextField("00h");
        panelSFR.add(fsr_hex, new AbsoluteConstraints(100, 100, 27, 20));

        x = 137;
        i = 7;
        y = 103;

        while(i>=0) {
            fsr_bit[i] = new JTextField();
            fsr_bit[i].setEnabled(false);
            fsr_bit[i].setBackground(Color.WHITE);
            panelSFR.add(fsr_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        // PortA
        portA_label = new JLabel("05h PORTA");
        panelSFR.add(portA_label, new AbsoluteConstraints(5, 120, 90, 20));

        portA_hex = new JTextField("00h");
        panelSFR.add(portA_hex, new AbsoluteConstraints(100, 120, 27, 20));

        x = 191;
        i = 4;
        y = 123;

        while(i>=0) {
            portA_bit[i] = new JTextField();
            portA_bit[i].setEnabled(false);
            portA_bit[i].setBackground(Color.WHITE);
            panelSFR.add(portA_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        // PortB
        portB_label = new JLabel("06h PORTB");
        panelSFR.add(portB_label, new AbsoluteConstraints(5, 140, 90, 20));

        portB_hex = new JTextField("00h");
        panelSFR.add(portB_hex, new AbsoluteConstraints(100, 140, 27, 20));

        x = 137;
        i = 7;
        y = 143;

        while(i>=0) {
            portB_bit[i] = new JTextField();
            portB_bit[i].setEnabled(false);
            portB_bit[i].setBackground(Color.WHITE);
            panelSFR.add(portB_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        // EEDATA
        eedata_label = new JLabel("08h EEDATA");
        panelSFR.add(eedata_label, new AbsoluteConstraints(5, 160, 90, 20));

        eedata_hex = new JTextField("00h");
        panelSFR.add(eedata_hex, new AbsoluteConstraints(100, 160, 27, 20));

        x = 137;
        i = 7;
        y = 163;

        while(i>=0) {
            eedata_bit[i] = new JTextField();
            eedata_bit[i].setEnabled(false);
            eedata_bit[i].setBackground(Color.WHITE);
            panelSFR.add(eedata_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        // EEADR
        eeadr_label = new JLabel("09h EEADR");
        panelSFR.add(eeadr_label, new AbsoluteConstraints(5, 180, 90, 20));

        eeadr_hex = new JTextField("00h");
        panelSFR.add(eeadr_hex, new AbsoluteConstraints(100, 180, 27, 20));

        x = 137;
        i = 7;
        y = 183;

        while(i>=0) {
            eeadr_bit[i] = new JTextField();
            eeadr_bit[i].setEnabled(false);
            eeadr_bit[i].setBackground(Color.WHITE);
            panelSFR.add(eeadr_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        //PCLATH
        pclath_label = new JLabel("0Ah PCLATH");
        panelSFR.add(pclath_label, new AbsoluteConstraints(5, 200, 90, 20));

        pclath_hex = new JTextField("00h");
        panelSFR.add(pclath_hex, new AbsoluteConstraints(100, 200, 27, 20));

        x = 191;
        i = 4;
        y = 203;

        while(i>=0) {
            pclath_bit[i] = new JTextField();
            pclath_bit[i].setEnabled(false);
            pclath_bit[i].setBackground(Color.WHITE);
            panelSFR.add(pclath_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        //INTCON
        intcon_label = new JLabel("0Bh INTCON");
        panelSFR.add(intcon_label, new AbsoluteConstraints(5, 220, 90, 20));

        intcon_hex = new JTextField("00h");
        panelSFR.add(intcon_hex, new AbsoluteConstraints(100, 220, 27, 20));

        x = 137;
        i = 7;
        y = 223;

        while(i>=0) {
            intcon_bit[i] = new JTextField();
            intcon_bit[i].setEnabled(false);
            intcon_bit[i].setBackground(Color.WHITE);
            panelSFR.add(intcon_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        //OPTION_REG
        optionReg_label = new JLabel("81h OPTION_REG");
        panelSFR.add(optionReg_label, new AbsoluteConstraints(5, 240, 90, 20));

        optionReg_hex = new JTextField("00h");
        panelSFR.add(optionReg_hex, new AbsoluteConstraints(100, 240, 27, 20));

        x = 137;
        i = 7;
        y = 243;

        while(i>=0) {
            optionReg_bit[i] = new JTextField();
            optionReg_bit[i].setEnabled(false);
            optionReg_bit[i].setBackground(Color.WHITE);
            panelSFR.add(optionReg_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        //TRISA
        trisA_label = new JLabel("85h TRISA");
        panelSFR.add(trisA_label, new AbsoluteConstraints(5, 260, 90, 20));

        trisA_hex = new JTextField("00h");
        panelSFR.add(trisA_hex, new AbsoluteConstraints(100, 260, 27, 20));

        x = 191;
        i = 4;
        y = 263;

        while(i>=0) {
            trisA_bit[i] = new JTextField();
            trisA_bit[i].setEnabled(false);
            trisA_bit[i].setBackground(Color.WHITE);
            panelSFR.add(trisA_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        //TRISB
        trisB_label = new JLabel("86h TRISB");
        panelSFR.add(trisB_label, new AbsoluteConstraints(5, 280, 90, 20));

        trisB_hex = new JTextField("00h");
        panelSFR.add(trisB_hex, new AbsoluteConstraints(100, 280, 27, 20));

        x = 137;
        i = 7;
        y = 283;

        while(i>=0) {
            trisB_bit[i] = new JTextField();
            trisB_bit[i].setEnabled(false);
            trisB_bit[i].setBackground(Color.WHITE);
            panelSFR.add(trisB_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        //EECON1
        eecon1_label = new JLabel("88h EECON1");
        panelSFR.add(eecon1_label, new AbsoluteConstraints(5, 300, 90, 20));

        eecon1_hex = new JTextField("00h");
        panelSFR.add(eecon1_hex, new AbsoluteConstraints(100, 300, 27, 20));

        x = 191;
        i = 4;
        y = 303;

        while(i>=0) {
            eecon1_bit[i] = new JTextField();
            eecon1_bit[i].setEnabled(false);
            eecon1_bit[i].setBackground(Color.WHITE);
            panelSFR.add(eecon1_bit[i], new AbsoluteConstraints(x, y, 12, 12));

            x+=18;
            i--;
        }

        mainGUI.add(scrollSFR);
        // *********

    }

    /**
     *
     * @param code Quelltext (String)
     * @brief Setzt den Quelltext in das entsprechende Textfeld ein.
     */
    public void setCodeView(String code) {
        codeArea.setText(code);
        codeArea.setCaretPosition(0);
    }

    /**
     * @brief Löscht den aktuellen Inhalt des Code-Fensters
     */
    public void clearCodeView() {
        codeArea.setText(null);
    }

    /**
     * 
     * @return toolBar (JToolBar)
     * @brief Erstellt die Toolbar mit den Icons/Buttons, die zur Steuerung der Anwendung am häufigsten gebraucht werden.
     */
    private JToolBar createToolBar() {

        toolBar = new JToolBar();
        toolBar.setRollover(true);
        toolBar.setFloatable(false);        
        toolBar.setMargin(new Insets(10,5,5,5));
        toolBar.setBounds(0, 0, 800, 30);

        ImageIcon open = control.getImageIcon("open");
        bt_open = new JButton();
        bt_open.setText("Öffnen");
        bt_open.setIcon(open);
        bt_open.setToolTipText("Programm öffnen");
        bt_open.addActionListener(this);
        toolBar.add(bt_open);


        ImageIcon reset = control.getImageIcon("reset");
        bt_reset = new JButton();
        bt_reset.setText("Reset");
        bt_reset.setIcon(reset);
        bt_reset.setToolTipText("Simulator zurücksetzen");
        bt_reset.addActionListener(this);
        toolBar.add(bt_reset);        


        toolBar.addSeparator();
        

        ImageIcon play = control.getImageIcon("play");
        bt_startPause = new JButton();
        bt_startPause.setText("Start");
        bt_startPause.setIcon(play);
        bt_startPause.setToolTipText("Programm starten");
        
        bt_startPause.addActionListener(startPauseAction);
        toolBar.add(bt_startPause);

        
        ImageIcon stop = control.getImageIcon("stop");
        bt_stop = new JButton();
        bt_stop.setText("Stop");
        bt_stop.setIcon(stop);
        bt_stop.setToolTipText("Simulation beenden");
        bt_stop.setEnabled(false);

        bt_stop.addActionListener(startPauseAction);
        toolBar.add(bt_stop);
        

        toolBar.addSeparator();
        

        ImageIcon step = control.getImageIcon("step");
        bt_step = new JButton();
        bt_step.setText("Next Step");
        bt_step.setIcon(step);
        bt_step.setToolTipText("Programm schrittweise ausführen");                
        bt_step.addActionListener(this);
        toolBar.add(bt_step);

        return toolBar;
    }

    /**
     * 
     * @param status (boolean)
     * @brief Zurücksetzen der Werte soll nur möglich sein, wenn eine Datei geladen ist.
     */
    public void setResetStatus(boolean status) {
        bt_reset.setEnabled(status);
        bt_startPause.setEnabled(status);
        bt_step.setEnabled(status);
        menuItem_reset.setEnabled(status);
    }

    /**
     * @brief Ändert die Beschriftung und das Icon des kombinierten Start/Pause-Buttons.
     * Abhängig von der aktuellen Anzeige wird entweder ein Start oder ein Pause (Fortsetzen) Button angezeigt.
     */
    public void toggleStartPauseButton() {

        String btText = bt_startPause.getText();

        if(btText.equals("Start") || btText.equals("Fortsetzen")) {
            ImageIcon playIcon = control.getImageIcon("pause");
            bt_startPause.setIcon(playIcon);
            bt_startPause.setText("Pause");
            bt_startPause.setToolTipText("Programm pausieren");
            
            bt_reset.setEnabled(false);
            menuItem_reset.setEnabled(false);

            bt_open.setEnabled(false);
            menuItem_openFile.setEnabled(false);
        }
        else {            
            ImageIcon startIcon = control.getImageIcon("play");
            bt_startPause.setIcon(startIcon);
            bt_startPause.setText("Fortsetzen");
            bt_startPause.setToolTipText("Programm fortsetzen");
            
            bt_reset.setEnabled(false); // user can only reset the simulator if button stopSimulation is pressed
            menuItem_reset.setEnabled(false);
            
            bt_open.setEnabled(false); // user can only open a new file if simulation is halted
            menuItem_openFile.setEnabled(false);
        }

    }

    /**
     * 
     * @return true | false
     * @brief Prüft, ob die Checkbox "Comport" aktiviert ist.
     */
    public boolean testComportCheckBox() {
        if(comport_check.isSelected()) return true;
        else return false;
    }


    /**
     * @brief Setzt die kombinierte Schaltfläche Start/Pause auf den Standard-Wert "Start"
     */
    public void setStartButton() {

        ImageIcon startIcon = control.getImageIcon("play");
        bt_startPause.setIcon(startIcon);
        bt_startPause.setText("Start");
        bt_startPause.setToolTipText("Simulation starten");

    }

    /**
     * 
     * @return result (int)
     * @brief Zeigt einen Dialog an, der darauf hinweist, dass ein Zurücksetzen des Simulators den Verlust aller aktuellen Werte mit sich führt.
     */
    public int showResetDialog() {

        Object[] options = {"Ja",
                    "Nein"};
        int result = JOptionPane.showOptionDialog(null, "Soll der Simulator wirklich zurückgesetzt werden?"+
                "\nAktuelle Werte gehen verloren!", "PICSim - Simulator zurücksetzen",
        JOptionPane.YES_NO_OPTION,
        JOptionPane.QUESTION_MESSAGE,  null, options, options[1]);

        return result;
    }

    /**
     * @brief Setzt die GUI und alle gespeicherten Werte zurück
     */
    public void resetGUI() {

        clearCodeView();
        control.clearFilePath();
        setResetStatus(false);
        
    }

    /**
     * @brief Aktualisiert die Anzeige der GUI mit den aktuellen Werten usw.
     */
    public void refreshGUI() {

        String tmp = "";
        int tmp_8bit[] = new int[8];
        int tmp_5bit[] = new int[5];


        // W-Reg
        tmp = Integer.toHexString(mem.getW());
        tmp = tmp.toUpperCase();
        if(tmp.length() < 2)
            wReg.setText("0"+tmp+"h");
        else
            wReg.setText(tmp+"h");
        // *********

        // PCL
        tmp = Integer.toHexString(mem.getPCL());
        tmp = tmp.toUpperCase();
        if(tmp.length() < 2)
            pcl.setText("0"+tmp+"h");
        else
            pcl.setText(tmp+"h");
        // *********

        // Bank0 & Bank1
        if(mem.getActualBank()) { // we are on bank1
            bank1_check.setSelected(true);
        }
        else {
            bank1_check.setSelected(false);
        }
        // *********

        // instruction counter
        instructionCounter.setText(" "+mem.getInstCounter());
        // *********

        // real time duration
        String time = calc.convertTimeToString(mem.getRealTimeDuration());        
        realTimeDuration.setText(" "+time);
        // *********

        // Stack view
        int complete_stack[] = mem.getStack();
        for(int i=0; i<8; i++) {
            tmp = Integer.toHexString(complete_stack[i]);
            tmp = tmp.toUpperCase();
            switch(tmp.length()) {
                case 1: stack[i].setText("000"+tmp+"h"); break;
                case 2: stack[i].setText("00"+tmp+"h"); break;
                case 3: stack[i].setText("0"+tmp+"h"); break;
                default: stack[i].setText(tmp+"h");
            }
        }
        // *********
        
        // set bank 0 values
        String value = "";
        for(int i=0; i<68; i++) {
            value = Integer.toHexString(mem.getSramValue(i));
            if(value.length()<2) bank0[i].setText("0"+value.toUpperCase()+"h");
            else bank0[i].setText(value.toUpperCase()+"h");
        }
        // *********



        // SFR values        

        // 01h TMR0
        tmp = Integer.toHexString(mem.getTMR0Reg());
        if(tmp.length() < 2)
            tmr0_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            tmr0_hex.setText(tmp.toUpperCase()+"h");

        tmp_8bit = calc.getSingleBitValues(8, mem.getTMR0Reg());

        for(int i=0; i<8; i++) {
            if(tmp_8bit[i] == 1) tmr0_bit[i].setBackground(colorBitSet);
            else tmr0_bit[i].setBackground(colorBitCleared);
        }
        

        // 02h PCL        
        tmp = Integer.toHexString(mem.getPCL());
        if(tmp.length() < 2)
            pclSFR_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            pclSFR_hex.setText(tmp.toUpperCase()+"h");

        tmp_8bit = calc.getSingleBitValues(8, mem.getPCL());

        for(int i=0; i<8; i++) {
            if(tmp_8bit[i] == 1) pclSFR_bit[i].setBackground(colorBitSet);
            else pclSFR_bit[i].setBackground(colorBitCleared);
        }

        // 03h STATUS
        tmp = Integer.toHexString(mem.getStatusRegValueSum());
        if(tmp.length() < 2)
            status_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            status_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<8; i++) {
            if(mem.getStatusRegValue(i) == 1) status_bit[i].setBackground(colorBitSet);
            else status_bit[i].setBackground(colorBitCleared);
        }

        // 04h FSR
        tmp = Integer.toHexString(mem.getFSRReg());
        if(tmp.length() < 2)
            fsr_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            fsr_hex.setText(tmp.toUpperCase()+"h");

        tmp_8bit = calc.getSingleBitValues(8, mem.getFSRReg());

        for(int i=0; i<8; i++) {
            if(tmp_8bit[i] == 1) fsr_bit[i].setBackground(colorBitSet);
            else fsr_bit[i].setBackground(colorBitCleared);
        }

        // 05h PORTA        
        tmp = Integer.toHexString(mem.getPORTARegValueSum());
        if(tmp.length() < 2)
            portA_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            portA_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<5; i++) {
            if(mem.getPORTARegValue(i) == 1) portA_bit[i].setBackground(colorBitSet);
            else portA_bit[i].setBackground(colorBitCleared);
        }

        // 06h PORTB
        tmp = Integer.toHexString(mem.getPORTBRegValueSum());
        if(tmp.length() < 2)
            portB_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            portB_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<8; i++) {
            if(mem.getPORTBRegValue(i) == 1) portB_bit[i].setBackground(colorBitSet);
            else portB_bit[i].setBackground(colorBitCleared);
        }

        // 07h -> not implemented!!

        // 08h EEDATA        
        tmp = Integer.toHexString(mem.getEEDATAReg());
        if(tmp.length() < 2)
            eedata_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            eedata_hex.setText(tmp.toUpperCase()+"h");

        tmp_8bit = calc.getSingleBitValues(8, mem.getEEDATAReg());

        for(int i=0; i<8; i++) {
            if(tmp_8bit[i] == 1) eedata_bit[i].setBackground(colorBitSet);
            else eedata_bit[i].setBackground(colorBitCleared);
        }

        // 09h EEADR
        tmp = Integer.toHexString(mem.getEEADRReg());
        if(tmp.length() < 2)
            eeadr_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            eeadr_hex.setText(tmp.toUpperCase()+"h");

        tmp_8bit = calc.getSingleBitValues(8, mem.getEEADRReg());

        for(int i=0; i<8; i++) {
            if(tmp_8bit[i] == 1) eeadr_bit[i].setBackground(colorBitSet);
            else eeadr_bit[i].setBackground(colorBitCleared);
        }

        // 0Ah PCLATH        
        tmp = Integer.toHexString(mem.getPCLATHRegValueSum());
        if(tmp.length() < 2)
            pclath_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            pclath_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<5; i++) {
            if(mem.getPCLATHRegValue(i) == 1) pclath_bit[i].setBackground(colorBitSet);
            else pclath_bit[i].setBackground(colorBitCleared);
        }

        // 0Bh INTCON        
        tmp = Integer.toHexString(mem.getINTCONRegValueSum());
        if(tmp.length() < 2)
            intcon_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            intcon_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<8; i++) {
            if(mem.getINTCONRegValue(i) == 1) intcon_bit[i].setBackground(colorBitSet);
            else intcon_bit[i].setBackground(colorBitCleared);
        }

        // 81h OPTION_REG
        tmp = Integer.toHexString(mem.getOptionRegValueSum());
        if(tmp.length() < 2)
            optionReg_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            optionReg_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<8; i++) {
            if(mem.getOptionRegValue(i) == 1) optionReg_bit[i].setBackground(colorBitSet);
            else optionReg_bit[i].setBackground(colorBitCleared);
        }

        // 82h, 83h, 84h -> Bank0

        // 85h TRISA
        tmp = Integer.toHexString(mem.getTrisARegValueSum());
        if(tmp.length() < 2)
            trisA_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            trisA_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<5; i++) {
            if(mem.getTrisARegValue(i) == 1) trisA_bit[i].setBackground(colorBitSet);
            else trisA_bit[i].setBackground(colorBitCleared);
        }

        // 86h TRISB
        tmp = Integer.toHexString(mem.getTrisBRegValueSum());
        if(tmp.length() < 2)
            trisB_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            trisB_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<8; i++) {
            if(mem.getTrisBValue(i) == 1) trisB_bit[i].setBackground(colorBitSet);
            else trisB_bit[i].setBackground(colorBitCleared);
        }

        // 87h -> not implemented!!

        // 88h EECON1        
        tmp = Integer.toHexString(mem.getEECON1RegValueSum());
        if(tmp.length() < 2)
            eecon1_hex.setText("0"+tmp.toUpperCase()+"h");
        else
            eecon1_hex.setText(tmp.toUpperCase()+"h");

        for(int i=0; i<5; i++) {
            if(mem.getEECON1RegValue(i) == 1) eecon1_bit[i].setBackground(colorBitSet);
            else eecon1_bit[i].setBackground(colorBitCleared);
        }
        

        // 89h -> not a physical layer

        // 8Ah, 8Bh -> Bank0

        // *********

        
    }


    /**
     *
     * @param start (int
     * @param end (int)
     * @param color (int)
     * @brief Hebt den Bereich zwischen <code>start</code> und <code>end</code> in der Code-Ansicht hervor.
     */
    public void highlightLine(int start, int end, int color) {

        Highlighter h = codeArea.getHighlighter();
        h.removeAllHighlights();

        try {
            if(color == 0) { // default (blue)
                h.addHighlight(start, end, DefaultHighlighter.DefaultPainter);
            }
            else // breakpoint
                h.addHighlight(start, end, new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR));
        }
        catch (BadLocationException ble) {
            System.out.println("Fehler! Highlightning = Bad Location");
            //ble.printStackTrace();
        }

       codeArea.setCaretPosition(start);

    }

    /**
     * @brief Setzt den Radio-Button im Menüeintrag "Simulation" auf Normal. Wird beim Zurücksetzen genutzt.
     */
    public void setSpeedNormal() {
        rbMenuItem_normalSpeed.setSelected(true);
    }

    /**
     * @brief Öffnet ein neues Fenster, das Informationen zum Simulator enthält.
     */
    public void showAboutWindow() {

        JFrame aboutGUI = new JFrame("About");
        aboutGUI.getContentPane().add(new JLabel("Version 0.6.3 - 02.05.2010"));
        aboutGUI.setSize(400,300);
        aboutGUI.setLocation(300, 300);
        aboutGUI.setVisible(true);
        aboutGUI.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    }


    /**
     * @brief Erzeugt ein neues Fenster, in dem eine Beschreibung über Breakpoints enthalten sind.
     * In diesem Fenster können die Breakpoints gespeichert werden.
     */
    public void showSettingsWindow() {

        String bp_description = 
                "<html>" +
                "<body>" +
                " Hier können Breakpoints (Haltepunkte) gesetzt werden.<br><br>" +
                " An diesen Punkten hält die Abarbeitung der Befehle an und wird erst fortgesetzt, wenn \"Fortsetzen\" gedrückt wird.<br><br>" +
                " Rechts kann die Zeile eingetragen werden, an der ein Breakpoint gesetzt werden soll." +
                "</body>" +
                "</html>";

        settingsGUI = new JFrame("Einstellungen");
        settingsGUI.setSize(400,300);
        settingsGUI.setLayout(null);
        settingsGUI.setLocation(300,300);

        JLabel bp_label = new JLabel("Breakpoints");
        bp_label.setBounds(5, 5, 150, 20);
        bp_label.setFont(new Font(null, 0, 16)); // set big font
        settingsGUI.add(bp_label);

        JLabel bp_descr = new JLabel();
        bp_descr.setText(bp_description);
        bp_descr.setBounds(5, 40, 250, 150);
        settingsGUI.add(bp_descr);
        
        JLabel bp_row[] = new JLabel[10];

        int y = 40;

        for(int i=0; i<bp_input.length; i++) {

            bp_row[i] = new JLabel("Zeile:");
            bp_row[i].setBounds(300, y, 50, 17);
            settingsGUI.add(bp_row[i]);

            bp_input[i] = new JTextField("");
            bp_input[i].setBounds(330, y, 35, 17);
            settingsGUI.add(bp_input[i]);
            y+=15;
        }


        // get actual (saved) breakpoints
        int actualBP[] = new int[10];
        actualBP = bp.getBreakpoints();
        for(int i=0; i<bp_input.length; i++) {
            if(actualBP[i] == 0) bp_input[i].setText("");
            else bp_input[i].setText(""+actualBP[i]);
        }


        // save + cancel buttons
        JButton save = new JButton("Speichern");
        save.setBounds(90, 220, 100, 30);
        save.addActionListener(new AbstractAction() {
          public void actionPerformed(ActionEvent e) {

                int bp_setting[] = new int[10];
                boolean saveOK = true;

                for(int i=0; i<bp_input.length; i++) {
                    if(bp_input[i].getText().equals("")) {
                        bp_setting[i] = 0;
                    }
                    else {
                        try {
                            bp_setting[i] = Integer.parseInt(bp_input[i].getText());
                        }
                        catch(NumberFormatException wrongNumFormat) {
                            saveOK = false;
                            //wrongNumFormat.printStackTrace();
                        }
                    }
                }

                if(saveOK) {
                    bp.saveBreakpoints(bp_setting);
                    settingsGUI.dispose();
                }
                else showDialog("error", "Falscher Breakpoint", "Konnte Breakpoints nicht speichern.\nEingabe(n) überprüfen!");

                
          }
        });
        
        settingsGUI.add(save);

        JButton cancel = new JButton("Abbrechen");
        cancel.setBounds(200, 220, 100, 30);
        cancel.addActionListener(new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            settingsGUI.dispose();
          }
        });
        settingsGUI.add(cancel);
        // *********

        settingsGUI.setVisible(true);
        settingsGUI.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    }

    /**
     * 
     * @param pType (String)
     * @param title (String)
     * @param content (String)
     * @brief Erzeugt verschiedene Dialoge (mögliche Arten: Warnung, Hinweis, Fehler und Frage)
     */
    public void showDialog(String pType, String title, String content) {

        // default:
        int type = JOptionPane.WARNING_MESSAGE;
        String titleAdd = "Hinweis";

        if(pType.equals("warning")) {
            type = JOptionPane.WARNING_MESSAGE;
            titleAdd = "Warnung";
        }
        if(pType.equals("error")) {
            type = JOptionPane.ERROR_MESSAGE;
            titleAdd = "Fehler";
        }
        if(pType.equals("info")) {
            type = JOptionPane.INFORMATION_MESSAGE;
            titleAdd = "Hinweis";
        }
        if(pType.equals("question")) {
            type = JOptionPane.QUESTION_MESSAGE;
            titleAdd = "Frage";
        }

        JOptionPane.showMessageDialog(mainGUI, content, titleAdd+" - "+title, type);


    }

    /**
     * @brief Ändert die Beschriftung des Start/Pause Buttons in der Toolbar und
     * lässt den Simulations-Thread warten.
     */
    public void waitOnBreakpoint() {

        toggleStartPauseButton();

        simTh.interrupt(); // stop Simulation Thread

    }

    /**
     * @brief Sperrt die Comport Checkbox
     */
    public void disableComportBox() {
        comport_check.setEnabled(false);
    }

    /**
     * @brief Hebt die Sperre der Comport Checkbox auf
     */
    public void enableComportBox() {
        comport_check.setEnabled(true);
    }
    
    /**
     *
     * @param e Eventsource (Object)
     * @brief Methode wird aufgerufen, wenn ein Interaktion des Benutzers (Mausklick o.ä.) mit der GUI stattfindet.
     * Der Parameter enthält verschiedenene Informationen über die Quelle und die Methode entscheidet anhand dieser Methoden
     * was geschehen soll.
     */
    public void actionPerformed(ActionEvent e) {
        
        if(e.getSource() == menuItem_closeApp){
            System.exit(0);
        }
        else if(e.getSource() == menuItem_openFile || e.getSource() == bt_open) {
            control.openFile();
        }
        else if(e.getSource() == menuItem_reset || e.getSource() == bt_reset) {
            control.resetSimulator();
        }
        else if(e.getSource() == bt_step) {
            control.nextStep(false);
        }
        else if(e.getSource() == menuItem_about){
            showAboutWindow();            
        }
        else if(e.getSource() == menuItem_Setting_bp) {
            showSettingsWindow();
        }
        else if(e.getSource() == comport_check) {          
            if(comport_check.isSelected()) {
              System.out.println("comport gedrückt (aktiviert)");
              control.communicateWithComport();
            }
        }
        else if(e.getSource() == menuItem_docu) {
            
            try {
                File pdfFile = new File(System.getProperty("user.dir"), "help.pdf");
                Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+pdfFile.getAbsolutePath());
                p.waitFor();
            } catch (IOException ex) {
                showDialog("warning", "Fehler", "Konnte PDF-Datei nicht öffnen!");
            } catch (InterruptedException ex) {
                showDialog("warning", "Fehler", "Konnte PDF-Datei nicht öffnen!");
            }


        }
        else if(e.getActionCommand().equals("Langsam")) {
            control.setSimulationSpeed("slow");
        }
        else if(e.getActionCommand().equals("Normal")) {
            control.setSimulationSpeed("normal");
        }
        else if(e.getActionCommand().equals("Schnell")) {
            control.setSimulationSpeed("fast");
        }
        else System.out.println("[GUI.actionPerformed():] Keine passende Abfrage für diese Aktion!!");

         
    }


    /**
     * @brief Spezieller (eigener) ActionListener, der den Simulations-Thread behandelt.
     * Durch die Schaltflächen Start, Stop und Pause werden bestimmte Aktionen durchgeführt.
     */
    ActionListener startPauseAction = new ActionListener() {

        Runnable simulationThread = new Runnable() {

            public void run() {
                control.run();
            }
        };

        public void actionPerformed(ActionEvent e) {

            if(e.getSource() == bt_startPause) {
                if(bt_startPause.getText().equals("Start") || bt_startPause.getText().equals("Fortsetzen")) {
                    toggleStartPauseButton();
                    bt_stop.setEnabled(true);
                    simTh = new Thread(simulationThread);
                    simTh.start();
                }
                else {
                    toggleStartPauseButton();
                    simTh.interrupt();
                }
            }
            else if(e.getSource() == bt_stop) {
                simTh.interrupt();

                control.stopSimulation();

                setStartButton();
                
                // set cursor to top of text area
                codeArea.setCaretPosition(0);

                //remove highlighting
                Highlighter h = codeArea.getHighlighter();
                h.removeAllHighlights();

                bt_reset.setEnabled(true);
                menuItem_reset.setEnabled(true);

                bt_open.setEnabled(true);
                menuItem_openFile.setEnabled(true);

                bt_stop.setEnabled(false);
            }


        }
    };

}
